package start.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import start.model.Street;
import start.service.IStreetService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class StreetCtrl {
	@Resource
	private IStreetService service;
	@RequestMapping("/street/query")
	public Map<String,Object> query( String code,int page, int rows){
		
		PageHelper.startPage(page,rows);
		List<Street> list=this.service.findAll(code);
		long total=((Page<Street>)list).getTotal();
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("rows", list);
		map.put("total", total);
		return map;
		

	}
	@RequestMapping("/street/save")
	public boolean save(Street bean) {
		try {
			this.service.save(bean);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
		
		
		
	}
	
	@RequestMapping("/street/remove/{id}")
	public boolean remove(@PathVariable("id") int id) {
		try {
			this.service.remove(id);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
		
	}
	
}
